package com.songlanyun.modules.comment.service.impl;

import cn.hutool.core.map.MapUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.songlanyun.modules.comment.dao.OrderGoodsCommentReplyDao;
import com.songlanyun.modules.comment.entity.OrderGoodsComment;
import com.songlanyun.modules.comment.entity.OrderGoodsCommentReply;
import com.songlanyun.modules.comment.service.OrderGoodsCommentReplyService;
import com.songlanyun.modules.comment.service.OrderGoodsCommentService;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.songlanyun.common.utils.PageUtils;
import com.songlanyun.common.utils.Query;
import reactor.core.publisher.Mono;

import javax.annotation.Resource;


@Service("orderGoodsCommentReplyService")
public class OrderGoodsCommentReplyServiceImpl extends ServiceImpl<OrderGoodsCommentReplyDao, OrderGoodsCommentReply> implements OrderGoodsCommentReplyService {


    @Resource
    private OrderGoodsCommentService orderGoodsCommentService;

    @Override
    public PageUtils queryPage(Map<String, Object> params) {

        Long shop_id = MapUtil.getLong(params, "shop_id");
        IPage<OrderGoodsCommentReply> page = this.page(
                new Query<OrderGoodsCommentReply>().getPage(params),
                new LambdaQueryWrapper<OrderGoodsCommentReply>()
                        .eq(shop_id != null, OrderGoodsCommentReply::getShopId, shop_id)
                        .orderByDesc(OrderGoodsCommentReply::getCreateTime)
        );

        return new PageUtils(page);
    }

    @Override
    public void saveReply(OrderGoodsCommentReply orderGoodsCommentReply, OrderGoodsComment comment) {
        orderGoodsCommentReply.setShopId(comment.getShopId());
        orderGoodsCommentReply.setUserId(comment.getUserId());
        this.baseMapper.insert(orderGoodsCommentReply);

    }

    @Override
    public List<OrderGoodsCommentReply> getByCommentId(Long id) {
        return this.baseMapper.selectList(
                new LambdaQueryWrapper<OrderGoodsCommentReply>()
                        .eq(OrderGoodsCommentReply::getCommentId, id)
                        .orderByDesc(OrderGoodsCommentReply::getCreateTime)
        );
    }


}
